package org.istt.domain;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;


/**
 * Workflow entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name="TBL_WORKFLOW"
    ,schema="dbo"
    ,catalog="onegate"
    ,uniqueConstraints=
    	@UniqueConstraint(columnNames={"name"})
)
public class Workflow extends BaseObject<Long> implements java.io.Serializable {
    // Fields    
     /**
	 * 
	 */
	private static final long serialVersionUID = -487767375719302403L;
	private Long id;
    private String name;
    private Set<WorkflowProcess> workflowProcesses = new HashSet<WorkflowProcess>(0);
    private Set<Category> categories = new HashSet<Category>(0);
    private boolean deletable;

    // Constructors

    /** default constructor */
    public Workflow() {
    }

    // Property accessors
    @Id @GeneratedValue(strategy=IDENTITY)
    
    @Column(name="ID", unique=true, nullable=false)

    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    @Column(name="NAME")

    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="workflow")

    public Set<WorkflowProcess> getWorkflowProcesses() {
        return this.workflowProcesses;
    }
    
    public void setWorkflowProcesses(Set<WorkflowProcess> workflowProcesses) {
        this.workflowProcesses = workflowProcesses;
    }
    
    
    public void addWorkflowProcess(WorkflowProcess item) {
        if (item == null) throw new IllegalArgumentException("Null item!");
        item.setWorkflow(this);
        workflowProcesses.add(item);
    }
    public void removeWorkflowProcess(WorkflowProcess item) {
        if (item == null) throw new IllegalArgumentException("Null item!");
        workflowProcesses.remove(item);
        item.setWorkflow(null);
    }
    
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="workflow")

    public Set<Category> getCategories() {
        return this.categories;
    }
    
    public void setCategories(Set<Category> categories) {
        this.categories = categories;
    }
    
    @Transient
    public boolean isDeletable() {
		return deletable;
	}

	public void setDeletable(boolean deletable) {
		this.deletable = deletable;
	}

	public boolean equals(Object o) {
		if (this == o) return true;
		if (!(o instanceof Workflow)) return false;

		final Workflow ps = (Workflow) o;


        if (!getName().equals(ps.getName())) return false;

		return true;
	}

	public int hashCode() {
		int result;
		result = name.hashCode();
		result = 29 * result;
		return result;
	}

	@Override
	public String toString() {
		return new StringBuilder("id = ").append(id)
					.append("name = ").append(name)
					.append("deleteable = ").append(deletable)
					.toString();
	}
}